package com.matrix.draft.rabbitmqspringboot.rabbitmq.callback;

import cn.hutool.core.lang.Console;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

/**
 * 消息回退回调
 */
@Component
public class AdvanceReturnedCallback implements RabbitTemplate.ReturnCallback {

    /**
     * 当消息的目的地不可达, 便会调用该方法.
     * @param message 消息本身
     * @param replyCode 消息码
     * @param cause 原因
     * @param exchangeName 交换机名
     * @param routingKey routingKey
     */
    @Override
    public void returnedMessage(Message message, int replyCode, String cause, String exchangeName, String routingKey) {
        Console.error("消息{}被交换机{}:{}退回了,原因:{}",message,exchangeName,routingKey,cause);
    }

}
